﻿using System;

namespace Hourglass.Qrobot.Utils
{
    public static class TimeHelper
    {
        /// <summary>
        /// 从1970.1.1到现在的毫秒数
        /// </summary>
        /// <returns></returns>
        public static long MilliscondFromSeventy()
        {
            var seventy = new DateTime(1970, 1, 1);
            return (DateTime.UtcNow.Ticks - seventy.Ticks)/10000;
        }

        /// <summary>
        /// 从1970.1.1到现在的秒数
        /// </summary>
        /// <returns></returns>
        public static long SecondFromSeventy()
        {
            return MilliscondFromSeventy()/1000;
        }

        /// <summary>
        /// 把从1970.1.1到现在的秒数转换为时间
        /// </summary>
        public static DateTime SecondsToDateTime(long secondsFromSeventy)
        {
            return new DateTime(1970, 1, 1).AddSeconds(secondsFromSeventy);
        }
    }
}
